package com.mooral.web.action.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.validator.DynaValidatorForm;

import com.mooral.bean.Beans;
import com.mooral.bean.Categories;
import com.mooral.bean.Merchant;
import com.mooral.bean.User;
import com.mooral.context.Context;
import com.mooral.web.action.MooralAction;
import com.mooral.web.util.SorterUtils;

public class NewAction extends MooralAction {

	@Override
	public ActionForward perform(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			Context context) throws Exception {
		
		DynaActionForm dform = (DynaActionForm) form;
		
		// Usuario
		dform.set("user", new User());
		
		// Categorias
		Categories categories = new Categories();
		categories.populate("SELECT id, parent_id as parentId, name FROM categories");
		dform.set("categories",  (new SorterUtils()).sortCategoriesByDependency(categories));
		
		
		return mapping.findForward(ACTION_SUCCESS);
	}

}
